package com.yiqi.lottery.framework;

import android.annotation.SuppressLint;
import android.util.Log;

import com.google.common.primitives.Ints;
import com.suozhang.framework.component.http.RxDataProcessFactory;
import com.suozhang.framework.framework.AM;
import com.suozhang.framework.utils.T;
import com.suozhang.framework.utils.logger.Logger;
import com.yiqi.lottery.entity.bo.*;
import com.yiqi.lottery.framework.api.LotteryApi;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Random;

public class DataServer {
    public static final String AD_URL = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1526622396135&di=258aa3f41df69e57d75f992b17b34cca&imgtype=0&src=http%3A%2F%2F58pic.ooopic.com%2F58pic%2F16%2F98%2F01%2F00F58PICfue.jpg";

    public static final String WIN = "http://img.zgzcw.com/zgzcw/matchCenter/team/images/20150127164537.jpg";
    public static final String DEFEAT = "http://img.zgzcw.com/zgzcw/matchCenter/team/images/20160728021003.jpg";


    public static List<String> getBannerData() {
        List<String> strings = new ArrayList<>();
        strings.add("http://img.500.com/upimages/ad/201804/20180402170924_1353.jpg");
        strings.add("http://img.500.com/upimages/ad/201804/20180403143107_3413.jpg");
        strings.add("http://img.500.com/upimages/sfc/201803/20180313151900_4909.jpg");
        strings.add("http://public.zgzcw.com/d/images/2018221517555242416_788.jpg");
        strings.add("http://public.zgzcw.com/d/images/2018431522718720789_715.jpg");
        return strings;
    }


    public static List<LuckySection> getNormalData() {

        List<LuckyBo> roomBos = new ArrayList<>();
        roomBos.add(0, new LuckyBo("请至少选择5个前区号码", getItems(35, 1, 0, false)));
        roomBos.add(1, new LuckyBo("请至少选择2个后区号码\n", getItems(12, 2, 1, false)));


        List<LuckySection> lifeMenuSections = new ArrayList<>();
        for (int i = 0; i < roomBos.size(); i++) {
            LuckyBo selectRoomBo = roomBos.get(i);
            lifeMenuSections.add(new LuckySection(true, selectRoomBo.getName()));
            for (int j = 0; j < selectRoomBo.getRoomList().size(); j++) {
                lifeMenuSections.add(new LuckySection(selectRoomBo.getRoomList().get(j)));
            }

        }
        return lifeMenuSections;
    }


    public static List<SelectItem> getItems(int num, int type, int dantuoType, boolean isDantuo) {
        List<SelectItem> selectItems = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            selectItems.add(new SelectItem(i + 1, type, false, dantuoType, isDantuo));
        }
        return selectItems;
    }

    public static List<LuckySection> getNormalRandomData() {

        List<LuckyBo> roomBos = new ArrayList<>();
        roomBos.add(0, new LuckyBo("请至少选择5个前区号码", getRandomItems(35, 1, 5)));
        roomBos.add(1, new LuckyBo("请至少选择2个后区号码", getRandomItems(12, 2, 2)));


        List<LuckySection> lifeMenuSections = new ArrayList<>();
        for (int i = 0; i < roomBos.size(); i++) {
            LuckyBo selectRoomBo = roomBos.get(i);
            lifeMenuSections.add(new LuckySection(true, selectRoomBo.getName()));
            for (int j = 0; j < selectRoomBo.getRoomList().size(); j++) {
                lifeMenuSections.add(new LuckySection(selectRoomBo.getRoomList().get(j)));
            }

        }
        return lifeMenuSections;
    }

    public static List<SelectItem> getLuckyRandomData() {
        List<SelectItem> selectItems = new ArrayList<>();
        List<LuckyBo> roomBos = new ArrayList<>();
        roomBos.add(0, new LuckyBo("请至少选择5个前区号码", getRandomItems(35, 1, 5)));
        roomBos.add(1, new LuckyBo("请至少选择2个后区号码", getRandomItems(12, 2, 2)));

        for (int i = 0; i < roomBos.size(); i++) {
            for (int j = 0; j < roomBos.get(i).getRoomList().size(); j++) {
                if (roomBos.get(i).getRoomList().get(j).isCheck()) {
                    selectItems.add(roomBos.get(i).getRoomList().get(j));
                }
            }
        }

        return selectItems;
    }


    public static List<SelectItem> getRandomItems(int num, int type, int random) {
        List<SelectItem> selectItems = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            selectItems.add(new SelectItem(i + 1, type, false));
        }
        int[] integers = randomCommon(1, num, random);
        for (int i = 0; i < selectItems.size(); i++) {
            for (int j = 0; j < integers.length; j++) {
                if (selectItems.get(i).getName() == integers[j]) {
                    selectItems.get(i).setCheck(true);
                }
            }
        }
        return selectItems;
    }


    public static int[] randomCommon(int min, int max, int n) {
        if (n > (max - min + 1) || max < min) {
            return null;
        }
        int[] result = new int[n];
        int count = 0;
        while (count < n) {
            int num = (int) (Math.random() * (max - min)) + min;
            boolean flag = true;
            for (int j = 0; j < n; j++) {
                if (num == result[j]) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                result[count] = num;
                count++;
            }
        }
        return result;
    }

    public static List<LuckySection> getDanshiData() {

        List<LuckyBo> roomBos = new ArrayList<>();
        roomBos.add(0, new LuckyBo("前区-胆码【选择1-4个号码】", getItems(35, 1, 1, true)));
        roomBos.add(1, new LuckyBo("前区-拖码【至少选择2个号码】", getItems(35, 1, 2, true)));
        roomBos.add(2, new LuckyBo("后区-胆码【最多选择1个号码】", getItems(12, 2, 3, true)));
        roomBos.add(3, new LuckyBo("后区-拖码【至少选择2个号码】", getItems(12, 2, 4, true)));


        List<LuckySection> lifeMenuSections = new ArrayList<>();
        for (int i = 0; i < roomBos.size(); i++) {
            LuckyBo selectRoomBo = roomBos.get(i);
            lifeMenuSections.add(new LuckySection(true, selectRoomBo.getName()));
            for (int j = 0; j < selectRoomBo.getRoomList().size(); j++) {
                lifeMenuSections.add(new LuckySection(selectRoomBo.getRoomList().get(j)));
            }

        }
        return lifeMenuSections;
    }

    /**
     *
     */
    public static final String[] FOOT_BALL_SPF = {"胜", "平", "负"};

    /**
     *
     */
    public static final String[] FOOT_BALL_RANG_SPF = {"让胜", "让平", "让负"};

    /**
     * 足球半全场类型
     */
    public static final String[] FOOT_BALL_HTEXY = {"主胜", "客不败", "主不败","客胜"};


    /**
     * 足球比分类型
     */
    public static final String[] FOOT_BALL_BF = {"1:0", "2:0", "2:1", "3:0", "3:1", "3:2", "4:0", "4:1", "4:2", "5:0", "5:1", "5:2", "胜其他",
            "0:0", "1:1", "2:2", "3:3", "平其他",
            "0:1", "0:2", "1:2", "0:3", "1:3", "2:3", "0:4", "1:4", "2:4", "0:5", "1:5", "2:5", "负其他"
    };

    /**
     * 足球半全场类型
     */
    public static final String[] FOOT_BALL_BQC = {"胜胜", "胜平", "胜负", "平胜", "平平", "平负", "负胜", "负平", "负负"};

    /**
     * 足球总进球类型
     */
    public static final String[] FOOT_BALL_ZJQ = {"0球", "1球", "2球", "3球", "4球", "5球", "6球", "7+球"};

    /**
     * 混合过关时，胜时可能组合，0为胜平负，1为让胜平负，2为总进球，3为半全场，4为比分
     */
    public static final int[][] FOOT_BALL_SHENG = {{0},{},{1,2,3,4,5,6,7},{0,3,6},{0,1,2,3,4,5,6,7,8,9,10,11,12}};

//    public static final int[][] FOOT_BALL_RANG_SHENG_1 = {{0,1},{2},{2}};
//
//    public static final int[][] FOOT_BALL_RANG_SHENG_2 = {{0},{0},{1,2}};

    /**
     * 混合过关时，平时可能组合，0为胜平负，1为让胜平负，2为总进球，3为半全场，4为比分
     */
    public static final int[][] FOOT_BALL_PING = {{1},{},{0,2,4,6,7},{1,4,7},{13,14,15,16,17}};

    /**
     * 混合过关时，负时可能组合，0为胜平负，1为让胜平负，2为总进球，3为半全场，4为比分
     */
    public static final int[][] FOOT_BALL_FU = {{2},{},{1,2,3,4,5,6,7},{2,5,8},{18,19,20,21,22,23,24,25,26,27,28,29,30}};

    /**
     * 篮球胜负类型
     */
    public static final String[] BASKET_BALL_SF = {"客胜", "主胜"};

    /**
     * 篮球胜负类型
     */
    public static final String[] BASKET_BALL_RANG_SF = {"让胜", "让负"};

    /**
     * 篮球大小分类型
     */
    public static final String[] BASKET_BALL_DXF = {"大分", "小分"};
    /**
     * 篮球胜分差类型
     */
    public static final String[] BASKET_BALL_SFC = {"1-5", "6-10", "11-15", "16-20", "21-25", "26+"};

    /**
     * 篮球胜分差类型
     */
    public static final String[] BASKET_BALL_SFC_2 = {"主胜(1-5)", "主胜(6-10)", "主胜(11-15)", "主胜(16-20)", "主胜(21-25)", "主胜(26+)",
            "客胜(1-5)", "客胜(6-10)", "客胜(11-15)", "客胜(16-20)", "客胜(21-25)", "客胜(26+)"
    };


    public static String getMoneyValue(double value) {
        value += 0.0001;
        DecimalFormat decimalFormat = new DecimalFormat("0.00");//构造方法的字符格式这里如果小数不足2位,会以0补足.
        decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
        return decimalFormat.format(value);
    }

    public static String getNewTime(String dateTime, long minusSecond) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Date dt2 = null;
        try {
            dt2 = sdf.parse(dateTime);
            return getTimeStrDateAndHour(dt2.getTime() - minusSecond * 1000);
        } catch (ParseException e) {
            e.printStackTrace();
        }
//继续转换得到秒数的long型
        return "";
    }

    public static boolean isTimeCanBuy(String dateTime, long minusSecond) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Date dt2 = null;
        try {
            dt2 = sdf.parse(dateTime);
            return (dt2.getTime() - minusSecond * 1000) > System.currentTimeMillis();
        } catch (ParseException e) {
            e.printStackTrace();
        }
//继续转换得到秒数的long型
        return false;
    }

    public static String getTimeStrDateAndHour(long time) {
        @SuppressLint("SimpleDateFormat") SimpleDateFormat mSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        Date dt = new Date(time);
        return mSdf.format(dt);
    }
}
